package com.hhdys.action;

import com.hhdys.jobs.TestJob1;
import org.apache.log4j.Logger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.ParseException;


/**
 * Created by zhangkai on 2017/3/5.
 */
@Controller
@RequestMapping("/task")
public class TashAction {
    private Logger log=Logger.getLogger(TashAction.class);
    @Autowired
    private Scheduler scheduler;
    @RequestMapping("/index")
    public String index(){
        JobDetail jobDetail= JobBuilder.newJob(TestJob1.class).withIdentity("testTask").build();
        try {
            CronTriggerImpl trigger= new CronTriggerImpl("testTrigger");
            trigger.setDescription("testTask");

            trigger.setCronExpression("0 * * * * ?");
            if(!scheduler.isStarted()){
                scheduler.start();
            }
            scheduler.scheduleJob(jobDetail,trigger);

        } catch (ParseException e) {
            e.printStackTrace();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        log.info("task========");
        return "admin/task/index";
    }
}
